package com.cea.papyrustest.uml.deletecommand;

import java.util.List;

import org.eclipse.uml2.uml.Constraint;

import com.cea.papyrus.core.commands.UMLElementDeleteCommand;

/**
 * Test Class for {@link Constraint} creation command
 * @author Remi Schnekenburger
 */
public class ConstraintDeleteCommandTest extends PapyrusCommandTest {

	/**
	 * Default constructor
	 * @param name name of the test case
	 */
	public ConstraintDeleteCommandTest(String name) {
		super(name);	
	}

	/* (non-Javadoc)
	 * @see com.cea.papyrustest.PapyrusCommandTest#setUp()
	 */
	@Override
	protected void setUp() throws Exception {
		super.setUp();
		List<Constraint> constraints = model.getOwnedRules();
		Constraint constraint = constraints.get(0);
		if(constraint == null) {
			fail("impossible to find a constraint");
		}
		papyrusCommand =new UMLElementDeleteCommand(constraint, constraint.getOwner());
	}

	/* (non-Javadoc)
	 * @see com.cea.papyrustest.PapyrusCommandTest#testExecute()
	 */
	@Override
	public void testExecute() {
		stack.execute(papyrusCommand);
		List<Constraint> constraints = model.getOwnedRules();
		assertNotNull("the constraint is not deleted", constraints);
		assertEquals("There should be no constraints in this list", 0, constraints.size());
		
		// undo
		stack.undo();
		constraints = model.getOwnedRules();
		assertNotNull("the constraint is not created", constraints);
		assertEquals("There should be one constraint in this list", 1, constraints.size());
		assertTrue("this is not a constraint", (constraints.get(0) instanceof Constraint));


		// redo
		stack.redo();
		constraints = model.getOwnedRules();
		assertNotNull("the constraint is not deleted", constraints);
		assertEquals("There should be no constraints in this list", 0, constraints.size());

	}
}
